package com.maikang.exammall.api;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.maikang.exammall.configuration.property.ApplicationProperty;
import com.maikang.exammall.util.EnvironmentUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class ActuatorController {
    private final ObjectMapper objectMapper;
    private ObjectNode health;

    @Autowired
    public ActuatorController(ApplicationProperty applicationProperty, ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
        health = objectMapper.createObjectNode();
        health.put("isAvailable", true);
        health.put("version", EnvironmentUtil.getVersion());
        health.put("component", applicationProperty.getName());
        health.put("description", applicationProperty.getDesc());
        health.put("stash-url", "https://gitee.com/torchcc");
        health.putArray("dependencies");
    }

    @GetMapping(path = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
    public String health() {
        return this.health.toString();
    }

    @GetMapping("/security/check")
    public void securityCheck() {

    }
}
